﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using StarTrek.Ship;
using StarTrek.Space;
using StarTrek.World;

namespace StarTrek.UI.Console
{
    public class DrawWorld
    {
        public static void DrawItem(Quadrant q, TextWriter tw)
        {
            int i = 0;
            int j = 0;
            foreach (iSpaceItem s in q)
            {
                if (i == 0) tw.Write("| ");
                if (s.isShipDocked() || (s.PresentShip != null))
                {
                    DrawItem(s.PresentShip, tw);
                }
                else
                {
                    DrawItem(s, tw);
                }
                tw.Write(" ");
                if (i == (Quadrant.QUAD_SIZE-1)) tw.WriteLine("|");


                i = ((i + 1) % (Quadrant.QUAD_SIZE ));
                if (i == 0) j = ((j+1)%(Quadrant.QUAD_SIZE));
            }
        }
        public static void DrawItem(iSpaceItem s, TextWriter tw)
        {
            string FormatString = " - ";
            if (s.GetType() != typeof(SpaceUnit)) FormatString = "({0})";
            tw.Write(FormatString, s.ToString().Substring(0, 1));
        }
        public static void DrawItem(iShip s, TextWriter tw)
        {
            tw.Write("[{0}]", s.ShipName.Substring(0, 1).ToUpper());
        }
    }
}
